package com.ruoyi.delivery.service.impl;

import com.ruoyi.delivery.domain.DelDeliveryDetail;
import com.ruoyi.delivery.domain.DelDeliveryOrderBatch;
import com.ruoyi.delivery.domain.DelDriver;
import com.ruoyi.delivery.domain.dto.MiniDelivery;
import com.ruoyi.delivery.mapper.DelDeliveryBatchMapper;
import com.ruoyi.delivery.mapper.DelDeliveryDetailMapper;
import com.ruoyi.delivery.mapper.DelDriverMapper;
import com.ruoyi.delivery.service.IDelDeliveryBatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DelDeliveryBatchServiceImpl implements IDelDeliveryBatchService {

    @Autowired
    private DelDeliveryBatchMapper deliveryBatchMapper;

    @Autowired
    private DelDriverMapper driverMapper;

    @Autowired
    private DelDeliveryDetailMapper deliveryDetailMapper;

    @Override
    public MiniDelivery getDeliveryOrderBatch(String driverId) {
        MiniDelivery miniDelivery = new MiniDelivery();

        // 从driverMapper中获取司机信息
        DelDriver driver = driverMapper.getDriverById(driverId);

        // 从deliveryBatchMapper中获取batch信息
        DelDeliveryOrderBatch batch = deliveryBatchMapper.getDeliveryBatchByVehicle(driver.getVehicleNo());

        //从deliveryDetailMapper中获取配送单明细信息
        List<DelDeliveryDetail> deliveryDetails = deliveryDetailMapper.getDeliveryDetailsByDeliveryId(batch.getDeliveryBatchId(), null, null, null);

        miniDelivery.setDeliveryOrderBatch(batch);
        miniDelivery.setDeliveryDetailList(deliveryDetails);

        return miniDelivery;
    }

}
